cc.Class({
	extends: cc.Component,

	properties: {
		nodeStart: cc.Node,
		nodeWeapon: cc.Node, // 武器
		nodeTouch: cc.Node, // 触摸
	},

	onLoad() {
		this.node.on(cc.Node.EventType.TOUCH_START, (event) => {
			// 方向
			this.nodeTouch.active = true;
			let pos = this.nodeTouch.parent.convertToNodeSpaceAR(
				event.getLocation()
			);
			this.nodeTouch.getComponent("Touch").setStartPos(pos);
			// 武器
			this.nodeWeapon.getComponent("Weapon").prepare();
		});

		this.node.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
			// 方向
			let pos = this.nodeTouch.parent.convertToNodeSpaceAR(
				event.getLocation()
			);
			let jsTouch = this.nodeTouch.getComponent("Touch");
			jsTouch.setEndPos(pos);

			// 武器
			cc.log(jsTouch.getForce());
			this.nodeWeapon.getComponent("Weapon").setForce(jsTouch.getForce());
			this.nodeWeapon.rotation = this.nodeTouch.rotation;
		});

		this.node.on(cc.Node.EventType.TOUCH_END, (event) => {
			// 方向
			this.nodeTouch.active = false;

			// 武器
			this.nodeWeapon.getComponent("Weapon").fire();
		});
	},

	start() {
		// 45
		cc.log(cc.v2(1, 1).signAngle(cc.v2(1, 0)));
		//90
		cc.log(cc.v2(0, 1).signAngle(cc.v2(1, 0)));
		// 180
		cc.log(cc.v2(-1, 0).signAngle(cc.v2(1, 0)));
		// 270
		cc.log(cc.v2(0, -1).signAngle(cc.v2(1, 0)));
		// 360
		cc.log(cc.v2(1, 0).signAngle(cc.v2(1, 0)));
	},

	// update (dt) {},

	onClick(event, data) {
		switch (data) {
			case "test": {
				this.nodeWeapon.getComponent("Weapon").fire();
				break;
			}
		}
	},
});
